
const app = getApp()

const utils = require("../../../utils/util")

Page({
    data: {
        inputValue : "",
        time : 0,
        record: {},
        chatList: [],
        myUrl: "https://it00zyq.oss-cn-beijing.aliyuncs.com/1a3306899b294e82ae289b1e843e19a1头像.jpg",
        hisUrl: "https://it00zyq.oss-cn-beijing.aliyuncs.com/2ce9569d774d42e39ab817d534d47eecboy-3.png",
        title: '聊天'
    },

    onLoad :function (options) {
        const companyName = options.companyName;
        if (companyName) {
          this.setData({
            title: companyName
          })
        }
        console.log("companyName", companyName);
        const userInfo = JSON.parse(wx.getStorageSync('userInfo'))
        const record = {
          id: 1,
          sendUserId: 1013,
          sendUserUrl: "https://it00zyq.oss-cn-beijing.aliyuncs.com/1a3306899b294e82ae289b1e843e19a1头像.jpg",
          acceptUserId: 2,
          companyName: "福家政有限公司",
          acceptUserUrl: "https://it00zyq.oss-cn-beijing.aliyuncs.com/2ce9569d774d42e39ab817d534d47eecboy-3.png",
          time: '2023/04/10 14:18:18',
          record: [
            {
              id: 1,
              text: "你好",
              time: '2023/04/10 14:18:18',
            }
          ]
        };
        this.setData({
            recordId : options.id,
            userInfo : userInfo,
            record: record
        })
        this.getChatList()
        this.getFriendInfo()
    },

    onshow: function (options) {
        this.getChatList()
    },

    publishMessage(){
        if (this.data.inputValue == "") {
            wx.showToast({
                icon: "none",
                title: '不能发送空消息',
            })
            return;
        }
        var that = this;
        const list = this.data.chatList;
        list.push({
          text: this.data.inputValue,
          sendUserId: this.data.userInfo.id,
          my: true
        })
        this.setData({
          chatList: list,
          inputValue: ''
        })
    },


    handleInput(e) {
        clearTimeout(this.data.time)
        var that = this;
        this.data.time = setTimeout(() => {
            that.getInputValue(e.detail.value)
        }, 200)
    },

    getInputValue(value) {
        this.setData({
            inputValue: value
        })
    },


    getChatList() {
        var that = this;
        const list = [
          {
            sendUserId: 1,
            my: false,
            text: "您好"
          },
          {
            sendUserId: 1013,
            my: true,
            text: "你好"
          }
        ]
        this.setData({
          chatList: list
        })
    },
    getFriendInfo() {
        var that = this;
        var friend_account_id,friend_avatarUrl;
       
    }

})